export default {
	namespaced: true,
	
	state: () => ({
		address: JSON.parse(uni.getStorageSync('address') || '{}'),
		token: uni.getStorageSync('token') || '', // 登录成功之后的token字符串
		userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		// 登录成功后再返回之前的页面功能
		// 重定向的Object对象{openType，from}
		// openType指返回之前页面的tabbar，也就是switchTab
		// from指返回之前页面的url路径
		redirectInfo: null
	}),
	
	mutations: {
		updateAddress(state, address) {
			state.address = address
			this.commit('m_user/saveAddressToStorage')
		},
		saveAddressToStorage(state) {
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		updateUserInfo(state, userinfo) {
			this.commit('m_user/saveUserInfoToStorage')
		},
		saveUserInfoToStorage(state, userinfo) {
			uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
		},
		updateToken(state, token) {
			state.token = token
			this.commit('m_user/saveTokenToStorage')
		},
		saveTokenToStorage(state, token) {
			uni.setStorageSync('token', state.token)
		},
		updateRedirectInfo(state, info) {
			state.redirectInfo = info
		}
	},
	
	getters: {
		addstr(state) {
			if(!state.address.provinceName) return ''
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}